import 'package:flutter/material.dart';
import 'package:get/get.dart';

extension FFWidgetExt on Widget {
  Widget get toExpand {
    return Expanded(
      child: this,
    );
  }

  Widget toExpandByFlex(
    int flex, {
    Key? key,
  }) {
    return Expanded(
      key: key,
      flex: flex,
      child: this,
    );
  }

  // 返回Obx
  Widget get toObx {
    return Obx(() => this);
  }

  // 返回Stack
  Widget toStack({
    Key? key,
    // children在上面
    bool childrenIsTop = true,
    List<Widget> children = const <Widget>[],
    StackFit fit = StackFit.loose,
    AlignmentGeometry alignment = AlignmentDirectional.topStart,
    Clip clipBehavior = Clip.hardEdge,
    TextDirection? textDirection,
  }) {
    return Stack(
      key: key,
      fit: fit,
      alignment: alignment,
      clipBehavior: clipBehavior,
      textDirection: textDirection,
      children: [
        if (childrenIsTop) this,
        ...children.map((e) => e).toList(),
        if (!childrenIsTop) this,
      ],
    );
  }

  /**
   * @title 使用Transform包含widget
   * @transform Matrix4.identity()..scale(p, p)
   */
  Widget toTransform({required Matrix4 transform,AlignmentGeometry? alignment}) {
    return Transform(
      alignment: alignment,
      transform: transform,
      child: this,
    );
  }
}
